﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using iSufeMVC4.Qiancun;

namespace iSufeMVC4.Areas.Qiancun.Controllers
{
    public class WeiboController : Controller
    {
        //
        // GET: /Qiancun/Weibo/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Faculty()
        {
            return View();
        }
        public ActionResult Register()
        {
            return View();
        }
        public ActionResult Location()
        {
            string text = Request.Form["LocationText"] ?? "";
            if (text.Length > 0) ViewData["TargetInfo"] = string.Format(@"""{0}""", text);
            return View(QcSerive.GetGeographyByWord(text,10));
        }
        public ActionResult StdCode()
        {
            string code = Request.Form["StdCodeText"] ?? "0";
            var users = QcSerive.GetStudentByCode(code);
            if (users.Count>0)
            {
                ViewData["TargetInfo"] = string.Format("{0}({1})",
                    users.First().StudentName,
                    users.First().StudentCode);
            }
            for (int year = 2008; year <= 2012; year++)
            {
                var user=users.Where(p => p.ParticipateYear == year).FirstOrDefault();
                if (user == null) 
                {
                    ViewData["Join" + year.ToString()] =   "-" ;
                    ViewData["Geography" + year.ToString()] = "-";
                    ViewData["Count" + year.ToString()] = "-";
                }
                else
                {
                    ViewData["Join" + year.ToString()] = @"成功参与";
                    var geo=QcSerive.GetGeographyByKey(user.GeographyKey??0);
                    ViewData["Geography" + year.ToString()] = geo.ProvinceName.Trim() + geo.CityName.Trim() + geo.AreaName.Trim() + geo.TownName.Trim() + geo.VillageName.Trim();
                    ViewData["Count" + year.ToString()] = QcSerive.GetFactTextAnswerCount(year, user.TeamLeaderKey??0);
                    
                }
                
            }
            return View();
        }


    }
}
